<template>
	<view class="discount-info_page">
    <car-number-input @numberInputResult="numberInputResult" :defaultStr="param.carNo"></car-number-input>

		<view class="content">

      <view class="grade_row">
				<view class="row">
					<view class="row_title">品牌</view>
					<input class="row_content" placeholder="请输入车辆品牌" type="text" v-model="param.carBrand" />
				</view>
			</view>
<!--			<view class="grade_row">-->
<!--				<view class="row">-->
<!--					<view class="row_title">车牌号</view>-->
<!--					<input class="row_content" placeholder="请输入车牌号" type="text" v-model="param.carNo" />-->
<!--				</view>-->
<!--			</view>-->
			<view class="grade_row">
				<view class="row">
					<view class="row_title">里程</view>
					<input class="row_content" placeholder="请输入车辆里程" type="text" v-model="param.carRange" />
				</view>
			</view>
		</view>
		<view class="submit">
			<button type="default" @click="getEditCar()">保存</button>
		</view>
	</view>
</template>

<script>
	import {
		editUserInfo
	} from '@/api/index.js'
	export default {
		data() {
			return {
				memInfo: {},
				param: {
					carNo: '川A',
					carBrand: '',
					carRange: ''
				},
      };
		},
		onLoad(option) {
			let memberInfo = JSON.parse(uni.getStorageSync('memberInfo'))
			this.memInfo = memberInfo.memberVo.member
			if (option.flag) {
				this.param.carNo = this.memInfo.carNo
				this.param.carBrand = this.memInfo.carBrand
				this.param.carRange = this.memInfo.carRange
			}
		},
		methods: {
			getEditCar() {
				uni.showLoading({
					title: '修改中...'
				})
				this.memInfo.carNo = this.param.carNo
				this.memInfo.carBrand = this.param.carBrand
				this.memInfo.carRange = this.param.carRange
				editUserInfo(this.memInfo).then(res => {
					uni.hideLoading()
					if (res.code === 200) {
						uni.reLaunch({
							url:'/pages/personal-center/index'
						})
					}
				})
			},
      numberInputResult(e) {
        this.param.carNo = e.trim()
        console.log('车牌--' + this.param.carNo)
      }
		}
	}
</script>

<style lang="scss">
	.discount-info_page {
		padding: 24rpx 30rpx 0rpx 30rpx;

		.content {
			background: #FFFFFF;
      margin-top: 24upx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;

			.grade_row {
				padding: 0rpx 32rpx;

				.row {
					display: flex;
					border-bottom: 1px solid #ededed;
					align-items: center;
					line-height: 98rpx;

					.row_title {
						font-size: 28rpx;
						color: #939391;
						line-height: 98rpx;
						width: 15%;
					}

					.row_content {
						font-size: 28rpx;
						//font-weight: 500;
						//color: #333333;
						line-height: 30rpx;
						margin-left: 72rpx;
					}
				}
			}

			.grade_row:nth-last-child(1) .row {
				border-bottom: none;
			}
		}

		.submit {
			button {
				line-height: 80rpx;
				width: 80%;
				background-color: #006241;
				margin: 30rpx auto;
				color: white;
        border-radius: 60upx;
			}
		}
	}
</style>